const form = document.querySelector(".register-form");
const btnReg = document.querySelector("#btn-register");
btnReg.addEventListener("click", async () => {
  const data = serialize(form, { hash: true, empty: true });
  console.log(data);
  if (data.username.value === "") return showToast("用户名不能为空", "red");
  if (data.password.value === "") return showToast("密码不能为空", "red");
  if (data.username.length < 8) return showToast("用户名不能小于8位", "red");
  if (data.password.length < 6) return showToast("密码不能小于6位", "red");
  try {
    const res = await getRegister(data);
    showToast(res.data.message, "green");
  } catch (err) {
    showToast(err.response.data.message, "red");
  }
});
